package com.java.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.entity.FoodInfo;
import com.java.entity.FoodType;
import com.java.service.FoodService;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;

@RestController
public class FoodController {

	@Autowired
	private FoodService foodService;

	@PostMapping("/getTypes")
	public TableRespone getSuggests(@RequestParam(required = false, defaultValue = "") String title,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return foodService.getTypes(title, page, size);
	}

	@PostMapping("/saveType")
	public BaseRespone saveType(@RequestBody FoodType info) {
		return foodService.saveType(info.getTypeId(), info.getTypeTitle(), info.getTypeIcon());
	}

	@PostMapping("/delType")
	public BaseRespone delType(@RequestParam(required = false) String typeId) {
		return foodService.delType(typeId);
	}

	@PostMapping("/getFoods")
	public TableRespone getFoods(@RequestParam(required = false, defaultValue = "") String foodTypeId,
			@RequestParam(required = false, defaultValue = "") String foodTitle,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return foodService.getFoods(foodTypeId, foodTitle, page, size);
	}

	@PostMapping("/saveFood")
	public BaseRespone saveFood(@RequestBody FoodInfo info) {
		return foodService.saveFood(info);
	}

	@PostMapping("/delFood")
	public BaseRespone delFood(@RequestParam(required = false) String foodId) {
		return foodService.delFood(foodId);
	}

}
